package com.avocado.bt.impl.action;

import com.avocado.bt.BTState;
import com.avocado.bt.IBTContext;
import com.avocado.bt.abs.action.ActionNode;
import com.avocado.mock.Player;

/**
 * @Author: zsh
 * @Date: 2023/10/17 12:49
 */
public class InitHpActionNode extends ActionNode {

    private final int maxHp;

    public InitHpActionNode(String param) {
        super(param);
        maxHp = Integer.parseInt(param);
    }

    @Override
    public BTState doUpdate(IBTContext context) {
        Player player = context.getPlayer();
        if (player.getHp() <= 0) {
            player.setHp(maxHp);
        }
        return BTState.Completed;
    }
}
